TESTS = $(wildcard *.t)
TARGETS = $(TESTS:.t=.trg)
ANS = $(TESTS:.t=.t.ans)
TC = ../compiler/tc
LR = ../utils/bin/loader
RLR = ../utils/bin/rloader

all:
	@echo "targets:"
	@echo "test       start testing process"
	@echo "ans        making answers (*.t.ans and *.r.ans) -"
	@echo "              you should check them manually"
	@echo "clean      remove temporary files"
	@echo "clean_all  remove temporary and answers"

test: $(TARGETS)
	@echo all tests passed

%.trg: %.t
	$(TC) $< -o t.tmp -r r.tmp
	$(LR) t.tmp -o t.tmp.txt
	$(RLR) r.tmp -o r.tmp.txt
	diff t.tmp.txt $*.t.ans
	diff r.tmp.txt $*.r.ans
	rm -f *.tmp
	@echo test $* passed

ans: $(ANS)
%.t.ans: %.t
	$(TC) $< -o t.tmp -r r.tmp
	$(LR) t.tmp -o $*.t.ans
	$(RLR) r.tmp -o $*.r.ans
	
clean:
	rm -f *.tmp*

clean_all: clean
	rm -f *.ans